public class RotateRight {
    public class ListNode{
        int val;
        ListNode next;
        ListNode(int val){
            this.val = val;
        }
        ListNode(int val,ListNode next){
            this.val = val;
            this.next = next;
        }
    }
    public ListNode rotateRight(ListNode head , int k){
        ListNode s = head;
        if(head == null||head.next==null){
            return head;
        }
        int size = 1;
        while(s.next!=null){
            s = s.next;
            size++;
        }
        s.next=head;
        k = size - k%size;
        for (int i = 0; i < k - 1; i++) {
            head = head.next;
        }
        s = head.next;
        head.next =null;
        return s;
    }
}
